package web.dao.Impl;

import web.bean.Fangchan;
import web.bean.XiaoQu;
import web.dao.FangChanDao;
import web.dao.XiaoQuDao;
import web.utils.DBUtil;

import java.util.List;

public class FangChanDaoImpl implements FangChanDao {
    @Override
    public List<Fangchan> findInfo(Integer limitParams1, Integer limitParams2, String startTime, String endTime, String name) {
        return DBUtil.findByWhere(Fangchan.class, "enterTime>=? and enterTime<=?  and suoshuxiaoqu like ? limit ?,?", startTime, endTime, "%" + name + "%", limitParams1, limitParams2);
    }

    @Override
    public int count(String startTime, String endTime, String name) {
        return DBUtil.findByWhere(Fangchan.class, "enterTime>=? and enterTime<=?  and suoshuxiaoqu like ? ", startTime, endTime, "%" + name + "%").size();
    }

    @Override
    public int add(Fangchan fangchan) {
        return DBUtil.insert(fangchan);
    }

    @Override
    public int del(Integer[] deleteId) {
        String where = "id in (";
        for (int i = 0; i < deleteId.length; i++) {
            where = where + "?";
            if (i != deleteId.length - 1) {
                where = where + ",";
            } else {
                where = where + ")";
            }
        }
        return DBUtil.delete(Fangchan.class, where, deleteId);
    }
    @Override
    public int editInfo(Fangchan fangchan) {
        return DBUtil.updateSelective(fangchan, "id=?", fangchan.getId());
    }

    @Override
    public Fangchan findFanChanById(Integer id) {
        return DBUtil.findOneByWhere(Fangchan.class,"id=?",id);
    }

    @Override
    public List<Fangchan> findNameAll() {
        return DBUtil.findAll(Fangchan.class);
    }
}
